/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2014-2019.
 * Description: entry of kbox module
 * Author: lichaoyue
 * Create: 2014-3-24
 */

#include "kbox_include.h"
#include "ddrramdriver.h"

/*
 * init kbox module
 */
static int __init kbox_init(void)
{
	int ret = 0;

	ret = kbox_core_init();
	if (ret < 0) {
		error("init core fail ret=%d\n", ret);
		goto fail1;
	}
	ret = kbox_proc_init();
	if (ret < 0) {
		error("init proc fail ret=%d\n", ret);
		goto fail2;
	}
#ifndef CONFIG_RTOS_KBOX_MINI
	ret = ddr_ram_init();
	if (ret < 0) {
		notice("Kbox not started. Use /proc/kbox/mem to set kbox mem\n");
		/*
		 * if no kbox_mem= in cmdline, when kernel boot, here will fail
		 * but we can configure kbox mem after kerel start by /proc/kbox/mem
		 * so here we can't goto fail, can't del proc file
		 */
	}
#endif
	notice("load OK\n");
	return 0;
fail2:
	kbox_core_fini();

fail1:
	return ret;
}

/*
 * cleanup kbox module
 */
static void __exit kbox_fini(void)
{
	kbox_proc_fini();

#ifndef CONFIG_RTOS_KBOX_MINI
	ddr_ram_exit();
#endif

	kbox_core_fini();
}

late_initcall(kbox_init);
module_exit(kbox_fini);
